function posture = getPostureFromMovement( dataList, curFrame )
%UNTITLED2 Summary of this function goes here
%   Detailed explanation goes here

     %Posture:
        %  0 - Unknonw
        % 1 = no loop
        % 2 - delta
        % 3 - alpha
        % 4 omega

        if  ~dataList(curFrame).IsLoop
                posture = 1;
        else  %if loop
            
            if dataList(curFrame).NumEndsVisible == 1
                posture = 2; %delta;
            elseif dataList(curFrame-1).Posture == 3
                posture = 3;
            elseif dataList(curFrame-1).Posture == 4
                posture = 4;
            else  %determine alpha or omega based on prior frames
                
                k = 1;
                while dataList(curFrame - k).IsLoop == 1 && curFrame ~= 1
                    k = k+1;
                end
                beforeLoopFrame = curFrame - k;
                deltaFrame = curFrame - k +1;
                
                %Verify that endA and B in each frame corresponds to eachother
                
                %Location of end A and B just before entering loop
                A1  = [dataList(beforeLoopFrame).Sktp_EndARow,...
                          dataList(beforeLoopFrame).Sktp_EndACol] ;
         
                B1 = [dataList(beforeLoopFrame).Sktp_EndBRow,...
                          dataList(beforeLoopFrame).Sktp_EndBCol] ;     
                
                [phi1, ~] = getLineAngles(A1, B1, dataList(beforeLoopFrame).FrameRows);
                     
                
                %Locations of end A and end B during delta posture
                A2 = [dataList(deltaFrame).Sktp_EndARow,...
                          dataList(deltaFrame).Sktp_EndACol] ;
                
                B2 = [dataList(deltaFrame).Sktp_EndBRow,...
                          dataList(deltaFrame).Sktp_EndBCol] ;
                
                [phi2, ~] = getLineAngles(A2, B2, dataList(deltaFrame).FrameRows);
                if getSmallestAngleBetween(phi1, phi2) > 90
                    temp = A2;
                    A2 = B2;
                    B2 = temp;
                    [phi2, ~] = getLineAngles(A2, B2, dataList(deltaFrame).FrameRows);
                end
                
               %Locations of end A and end B during current (alpha or omega)posture
                A3 = [dataList(curFrame).Curv_EndARow,...
                          dataList(curFrame).Curv_EndACol] ;
                
                B3 = [dataList(curFrame).Curv_EndBRow,...
                          dataList(curFrame).Curv_EndBCol] ;
                
                [phi3, ~] = getLineAngles(A3, B3, dataList(deltaFrame).FrameRows);
                 if getSmallestAngleBetween(phi2, phi3) > 90
                    temp = A3;
                    %A3 = B3;
                    B3 = temp;
                   
                end  
               
               
                %Vector from tail to head as head becomes obscured
                AB22 = getVector(A2,B2);

                %Vector from tail as head becomes obscured to head before it is
                %obscured
                AB21 = getVector(A2,B1);

                %Vector from tail as head becomes obscured to head after it
                %reapears
                AB23 = getVector(A2,B3);


                x = sign( cross([AB22,0],[AB21,0]));
                y = sign( cross([AB22,0],[AB23,0]));
                if x ~= y
                    posture = 3;    %alpha
                else
                    posture = 4;  %omega
                end
            end
        end
end

